﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for TinTucDAO
/// </summary>
public class TinTucDAO:AbstractDAO
{
	public TinTucDAO(String strPath)
        : base(strPath)
    {

    }
    ~TinTucDAO()
    {
        base.Dispose();
    }

    public DataSet SelectTinTucAll()
    {
        DataSet ds;
        try
        {
            ds = new DataSet();
            base.sql = "usp_SelectTinTucAll";
            base.FillDataSet(ref ds, "SelectTinTucAll");
            return ds;
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
        finally
        {
            base.CleanUpObject();
        }
    }

    public DataSet SelectTinTucAll_Summary(int length)
    {
        DataSet ds;
        try
        {
            ds = new DataSet();
            base.sql = "usp_SelectTinTucAll_Summary";
            
            base.InitializeCommand();

            base.AddParameter("@NoiDungTinTucLength",
            SqlDbType.Int, 10, length);

            base.FillDataSet(ref ds, "SelectTinTucAll_Summary");
            return ds;
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
        finally
        {
            base.CleanUpObject();
        }
    }

    public DataSet SelectTinTuc(int id)
    {
        DataSet ds;
        try
        {
            ds = new DataSet();
            base.sql = "usp_SelectTinTuc";
            base.InitializeCommand();

            base.AddParameter("@id",
            SqlDbType.Int, 10, id);

            base.FillDataSet(ref ds, "SelectTinTuc");
            return ds;
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
        finally
        {
            base.CleanUpObject();
        }
    }

    public Boolean InsertTinTuc(TinTucDTO tt)
    {
        try
        {
            base.sql = "usp_InsertTinTuc";
            base.InitializeCommand();

            base.AddParameter("@TieuDe",
            SqlDbType.NVarChar, 100, tt.TieuDe);

            base.AddParameter("@NoiDung",
            SqlDbType.NText, 10000, tt.NoiDung);

            base.AddParameter("@idNguoiDung",
            SqlDbType.UniqueIdentifier, 100, tt.IdNguoiDung);

            base.AddParameter("@HinhMinhHoa",
            SqlDbType.NVarChar, 200, tt.HinhMinhHoa);

            return ExecuteStoredProcedure();
        }
        catch (System.Exception ExceptionErr)
        {
            throw new Exception(ExceptionErr.Message, ExceptionErr.InnerException);

        }
    }

    public Boolean UpdateTinTuc(TinTucDTO tt, int type)
    {
        try
        {
            base.sql = "usp_UpdateTinTuc";
            base.InitializeCommand();

            base.AddParameter("@id",
            SqlDbType.Int, 10, tt.Id);

            base.AddParameter("@TieuDe",
            SqlDbType.NVarChar, 100, tt.TieuDe);

            base.AddParameter("@NoiDung",
            SqlDbType.NText, 10000, tt.NoiDung);

            base.AddParameter("@HinhMinhHoa",
            SqlDbType.NVarChar, 200, tt.HinhMinhHoa);

            base.AddParameter("@type",
            SqlDbType.Int, 10, type);

            return ExecuteStoredProcedure();
        }
        catch (System.Exception ExceptionErr)
        {
            throw new Exception(ExceptionErr.Message, ExceptionErr.InnerException);

        }
    }

    public Boolean DeleteTinTuc(int id)
    {
        try
        {
            base.sql = "usp_DeleteTinTuc";
            base.InitializeCommand();

            base.AddParameter("@id",
            SqlDbType.Int, 10, id);

            return ExecuteStoredProcedure();
        }
        catch (System.Exception ExceptionErr)
        {
            throw new System.Exception(ExceptionErr.Message,
            ExceptionErr.InnerException);
        }
    }
}
